package com.mdd.admin.controller.yylq;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.yylq.ITAppProductService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.validate.yylq.TAppProductCreateValidate;
import com.mdd.admin.validate.yylq.TAppProductSearchValidate;
import com.mdd.admin.validate.yylq.TAppProductUpdateValidate;
import com.mdd.admin.vo.yylq.TAppProductDetailVo;
import com.mdd.admin.vo.yylq.TAppProductListedVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/adminapi/yylq/product")
@Api(tags = "羊羊领企---领企管家---产品管理")
public class TAppProductController {

    @Resource
    ITAppProductService iTAppProductService;

    @GetMapping("/list")
    @ApiOperation(value="app产品列表")
    public AjaxResult<PageResult<TAppProductListedVo>> list(@Validated PageValidate pageValidate,
                                                            @Validated TAppProductSearchValidate searchValidate) {
        PageResult<TAppProductListedVo> list = iTAppProductService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="app产品详情")
    public AjaxResult<TAppProductDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        TAppProductDetailVo detail = iTAppProductService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "app产品新增")
    @PostMapping("/add")
    @ApiOperation(value="app产品新增")
    public AjaxResult<Object> add(@Validated @RequestBody TAppProductCreateValidate createValidate) {
        iTAppProductService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "app产品编辑")
    @PostMapping("/edit")
    @ApiOperation(value="app产品编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody TAppProductUpdateValidate updateValidate) {
        iTAppProductService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "app产品删除")
    @PostMapping("/del")
    @ApiOperation(value="app产品删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iTAppProductService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
